import {chooseMedia} from "../../utils/sfz"
import {isRegister,addReader} from "../../apis/gyt"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    idcard_res:{}, url:"",
    isRegister:false,
    photo:"",
    bzSuccess:false,
    result:{}
  },
  async onLoad(){
    //var res=await isRegister("422302198104050332");
    //wx.tts.speak({text:"你好"});
  },
  async addReader(){
    const regex = /^1[3-9]\d{9}$/;
    if(!regex.test(this.data.photo)){
      return wx.showToast({title: '请输入正确的手机号',});
    }
    var res= await addReader(this.data.idcard_res,this.data.photo);
   
    if(res.code==200){
      
        this.setData({bzSuccess:true,result:res});
    }
    else{
      return wx.showToast({title: '办证失败请联系我们解决'});
    }

  },
  async chooseMedia(){
    var _that=this;
    var r=await  chooseMedia();

    var res=await isRegister(r.idcard_res.id.text);
    if(res){
        wx.showToast({title: '读者已经注册'});
    }
    _that.setData({
      idcard_res:r.idcard_res, 
      url:r.tempFilePath,
      isRegister:res
    })

  },
})